package com.chahua.organized.qo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import cn.afterturn.easypoi.handler.inter.IExcelDataModel;
import cn.afterturn.easypoi.handler.inter.IExcelModel;
import com.chahua.organized.constant.CommonConstant;
import com.chahua.organized.entity.Department;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.Objects;

/**
 * @author chahua
 * @date 2022/4/9 23:20
 **/
@Data
@NoArgsConstructor
public class DepartmentMemberInput  implements IExcelDataModel, IExcelModel {

    /**
     * 行号
     */
    private int rowNum;

    /**
     * 错误消息
     */
    private String errorMsg;

    @Excel(name = "*姓名")
    @NotBlank(message = "[姓名]不能为空")
    @Pattern(regexp = CommonConstant.NAME_REGEXP, message = "成员名称不能含有\"'&<>()+%这些特殊字符，且长度不能超过95个字符")
    private String name;

    @Excel(name = "*手机号")
    @NotBlank(message = "[手机号]不能为空")
    @Pattern(regexp = CommonConstant.PHONE, message = "手机号码格式不正确")
    @Size(max = 20, message = "手机号码长度应小于等于20")
    private String phone;

    @Excel(name = "邮箱")
    @Pattern(regexp = CommonConstant.EMAIL, message = "电子邮箱格式不正确")
    @Size(max = 30, message = "电子邮箱长度应小于等于30")
    private String email;


    @Excel(name = "是否部门主管", replace = {"否_0", "是_1"})
    private Integer isManager;

    @Excel(name = "职位")
    private String post;

    @ExcelEntity(name = "所属部门")
    private Department department;

    // 重写hashcode和equals方法，用于比较excel中手机号+姓名是否重复
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DepartmentMemberInput that = (DepartmentMemberInput) o;
        return Objects.equals(name, that.name) && Objects.equals(phone, that.phone);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, phone);
    }
}


